﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Linq;

namespace JetRetail
{
    public partial class AddGiftCertificateForm : Form
    {
        JetRetailDB DB;

        string sCashier;

        DrvFRLib.IDrvFR47 ShtrihM;

        string sCheckNumber;

        public AddGiftCertificateForm(JetRetailDB DB, string sCashier, DrvFRLib.IDrvFR47 ShtrihM, string sCheckNumber)
        {
            this.DB = DB;

            this.sCashier = sCashier;

            this.ShtrihM = ShtrihM;

            this.sCheckNumber = sCheckNumber;

            InitializeComponent();
        }

        private void Series_TextChanged(object sender, EventArgs e)
        {
            OK.Enabled = ((Series.Text.Trim().Length > 0) && (Number.Text.Trim().Length > 0));
        }

        private void Number_TextChanged(object sender, EventArgs e)
        {
            OK.Enabled = ((Series.Text.Trim().Length > 0) && (Number.Text.Trim().Length > 0));
        }

        private void OK_Click(object sender, EventArgs e)
        {
            try
            {


                /*
                int iAmount = DB.ДобавитьПС(Series.Text.Trim(), Number.Text.Trim(), sCashier, (byte)PaymentType.SelectedIndex).First().Номинал.Value;

                ShtrihM.Password = 30;
                ShtrihM.SysAdminCancelCheck();

                ShtrihM.Password = 1;
                ShtrihM.CheckType = 0;
                if (ShtrihM.OpenCheck() != 0)
                {
                    MessageBox.Show(ShtrihM.ResultCodeDescription, "Jet-Розница", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ShtrihM.StringForPrinting = "Сертификат";
                ShtrihM.Quantity = 1;
                ShtrihM.Price = iAmount;
                if (ShtrihM.SaleEx() != 0)
                {
                    MessageBox.Show(ShtrihM.ResultCodeDescription, "Jet-Розница", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ShtrihM.Summ1 = (PaymentType.SelectedIndex == 0) ? (iAmount) : (0);
                ShtrihM.Summ2 = (PaymentType.SelectedIndex == 0) ? (0) : (iAmount);
                ShtrihM.Summ3 = 0;
                ShtrihM.Summ4 = 0;
                ShtrihM.DiscountOnCheck = 0;
                ShtrihM.StringForPrinting = "";
                if (ShtrihM.CloseCheck() != 0)
                {
                    MessageBox.Show(ShtrihM.ResultCodeDescription, "Jet-Розница", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                MessageBox.Show("Сейчас будет напечатана копия чека.", "Jet-Розница", MessageBoxButtons.OK, MessageBoxIcon.Information);

                ShtrihM.UseReceiptRibbon = true;
                ShtrihM.UseJournalRibbon = false;
                ShtrihM.StringForPrinting = " ";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = " ";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "        ОДО \"На Ульяновской\"";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "            УНП 190406722";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "------------------------------------";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "Копия чека №" + sCheckNumber + " от " + DateTime.Now.ToShortDateString();
                for (int i = (36 - ShtrihM.StringForPrinting.Length) / 2; i > 0; i--) ShtrihM.StringForPrinting = " " + ShtrihM.StringForPrinting;
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "------------------------------------";
                ShtrihM.PrintString();

                ShtrihM.StringForPrinting = "Подарочный сертификат";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "1 ед. по " + (int)iAmount + " руб.";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "Сумма: " + (int)iAmount + " руб.";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "------------------------------------";
                ShtrihM.PrintString();

                ShtrihM.StringForPrinting = "ИТОГО: " + (int)iAmount + " руб.";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = " ";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = " ";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = " ";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = " ";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = " ";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = " ";
                ShtrihM.PrintString();

                ShtrihM.CutType = false;
                ShtrihM.CutCheck();

                ShtrihM.StringForPrinting = "        ОДО \"На Ульяновской\"";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "        ул. Ульяновская, 41";
                ShtrihM.PrintString();
                ShtrihM.StringForPrinting = "          магазин \"Дезира\"";
                ShtrihM.PrintString();
                */
                Close();
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.Message, "Jet-Розница", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void AddGiftCertificateForm_Load(object sender, EventArgs e)
        {
            PaymentType.SelectedIndex = 0;
        }
    }
}